package com.jinloes.webfit;

import com.jinloes.webfit.persistence.UserTest;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

@Component("userValidator")
public class UserValidator implements Validator {

	@SuppressWarnings("rawtypes")
	public boolean supports(Class clazz) {
		return UserTest.class.equals(clazz);
	}

	public void validate(Object target, Errors e) {
		UserTest user = (UserTest)target;
		if(!user.getPassword().equals(user.getConfirmPassword())) {
			e.rejectValue("confirmPassword", "password.mismatch", "Passwords do not match");
		}
	}

}
